<template>
	<view class="content">

		<waterfall-flow :list="postList"></waterfall-flow>
		<image class="postBtn" @click="publishPost" src="/static/post.png"></image>
	</view>
</template>

<script>
	// 瀑布流组件
	import WaterfallFlow from '@/components/nairenk-waterfall-flow/nairenk-waterfall-flow.vue';
	import base from '@/common/base.js'
	export default {
		data() {
			return {
				page: 1,
				start: 0,
				end: 0,
				postList: [], // 列表
				loading: true
			}
		},
		onLoad() {
			this.$data;
			this.getList();
		},
		onReachBottom() {
			this.page++;
			this.loading = true;
		},
		methods: {
			//发布帖子的方法
			publishPost() {
				//如果用户未登录就提示用户先登录
				if (base.coach == null) {
					uni.showToast({
						icon: 'none',
						title: '请先登录'
					});
					uni.navigateTo({
						url: '/pages/login/login'
					})
				} else {
					uni.navigateTo({
						url: '/pages/post/publishPost'
					})
				}
			},
			//想服务器发送请求，获取所有帖子列表
			getList() {

				uni.request({
					url: base.urlPrefix + 'yoga_app/post/coachGetAllPost',
					success: (res) => {
						this.postList = res.data.list;
					}
				});
			}
		},
		components: {
			WaterfallFlow
		}

	}
</script>

<style>
	.postBtn {
		width: 10vw;
		height: 10vw;
		position: fixed;
		bottom: 20rpx;
		right: 20rpx;
		border: solid 1upx #fff;
		border-radius: 100%;
		background-color: #FF0000;
	}
</style>
